package com.qf.swagger1.controller;

import com.qf.swagger1.domain.R;
import com.qf.swagger1.domain.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/user")
@Api(tags = "用户模块API接口")
public class UserController {

    @GetMapping
    @ApiOperation("查询全部用户")
    public R findAll(){
        List<User> users = new ArrayList<>();
        User user = new User();
        user.setId(1);
        user.setUsername("zs");
        user.setPassword("123");
        users.add(user);

        user = new User();
        user.setId(2);
        user.setUsername("ls");
        user.setPassword("234");
        users.add(user);

        user = new User();
        user.setId(3);
        user.setUsername("ww");
        user.setPassword("456");
        users.add(user);

        return R.success(users);
    }

    @PostMapping
    @ApiOperation("新增用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "新增用户的用户名",required = true),
            @ApiImplicitParam(name = "pwd",value = "新增用户的密码",required = true)
    })
    public R add(String name,String pwd,@RequestBody User user){
        System.out.println("add:" + user);
        System.out.println("name:" + name);
        System.out.println("pwd:" + pwd);

        return R.success("add success...");
    }
}
